package day1206_2;

public class Shop  implements  Runnable{
    public void run(){
        while(true){
            subStock();
        }
    }

    int  stock=1;
    //让库存-1
    synchronized  void subStock(){
        if(stock==0){
            System.out.println("没库存了");
            System.exit(0);
        }
        Thread.yield();//让某个线程执行时，让出cpu
        stock--;
        System.out.println("剩余库存"+stock);
    }


}


